package com.gitee.deament.server.core.data.storage.impl;

import com.gitee.deament.server.core.data.storage.UserStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 基于内存的鉴权存储
 * @author Deament
 */
public class MemoryUserStorage implements UserStorage {
    Logger logger= LoggerFactory.getLogger(this.getClass());
    private  static ConcurrentHashMap<String,Object> userMap =  new ConcurrentHashMap(60);

    @Override
    public void authBind(String channelId) {
        userMap.put(channelId,new Date());
        logger.info("当前登录成功用户数"+userMap.size());
    }

    @Override
    public boolean checkIsAuth(String channelId) {
        Object o = userMap.get(channelId);
        return o!=null;
    }

    @Override
    public void authDelete(String channelId) {
        userMap.remove(channelId);
    }
}
